<?php

namespace App\Api;

use App\Http\Controllers\Controller;
use App\Http\Requests\LoginRequest;
use Auth;
use App\Models\Admin;

/**
 * 后台用户登录
 * Class LoginController
 * @package App\Api
 */
class LoginController extends Controller
{
//    用户登录
    public function login(LoginRequest $request)
    {
        $isLogin = Auth::guard('admin')->attempt(['mobile' => $request->mobile, 'password' => $request->password]);
        if ($isLogin) {
            $token = Auth::guard('admin')->user()->createToken('token-name');
            return ['message' => '登录成功', 'token' => $token->plainTextToken];
        }
        return $this->error('账号或者密码错误');
    }
}
